package crypt

import (
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
)

type Sha256 struct {
	EncryptData []byte
}

func (s *Sha256) Encrypt(data []byte) *Sha256 {
	h := sha256.New()
	h.Write(data)
	s.EncryptData = h.Sum(nil)
	return s
}

func (s *Sha256) ToHex() string {
	return hex.EncodeToString(s.EncryptData)
}

func (s *Sha256) ToB64() string {
	return base64.StdEncoding.EncodeToString(s.EncryptData)
}

func NewSha256() *Sha256 {
	return &Sha256{}
}
